import pandas as pd
from xlsxwriter import Workbook


def readTxt():
    txtPath = "E:\\disgassi\\712310050\\Result.txt"
    with open(txtPath, 'r') as file:
        lines = file.readlines()
    data = []
    for line in lines:
        line = line.strip()
        if line:
            line = line.split(',')
            data.append(line)
    # print(data)
    return data


def writerXlsx():
    xlsxPath = "C:/Users/1234/Desktop/光学需求3/tmp.xlsx"
    excelWriter = pd.ExcelWriter(xlsxPath, engine='xlsxwriter')
    sheetName = 'Sheet1'
    startRow = 0
    startCol = 0
    datat = readTxt()
    count = 1
    for data in datat:
        # 创建DataFrame
        df = pd.DataFrame(data)
        df.to_excel(excelWriter, sheet_name=sheetName, startrow=startRow, startcol=startCol, index=False)
        startCol += 1
        count += 1
        if count % 2 != 0 and count != 1:
            startCol += 1
    excelWriter.save()


if __name__ == '__main__':
    writerXlsx()
